package experiment1;
import java.util.*;

public class guessnumber {
    public static void main(String[] args) {
        int num = (int)(Math.random()*5316); //返回大小在0到5316之间的整数
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入整数，在0到5316之间");
        int a = -1;
        int i = 0;
        while (a!=num&&i<10){
            while (!scan.hasNextInt()) {
                // 输入错误的信息
                System.out.printf("输入的数据类型有问题！请再次输入。(你还有%d次机会)\n",10-i);
                scan = new Scanner(System.in);
            }
            a = scan.nextInt();
            if (a<0||a>5316) {
                System.out.printf("输入的数要在0到5316之间！请再次输入。（你还有%d次机会）\n",10-i);
                scan = new Scanner(System.in);
                continue;
            }
            if (a!=num)
                System.out.println("错了");
            i++;
        }
        if (a == num)
            System.out.println("恭喜你，猜对了！");
        else
            System.out.println("很遗憾，你没有机会了");
    }
}
